import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { User } from 'src/types/user.interface';

@Injectable()
export class UserService {
    constructor(@InjectModel('User') private userModel:Model<User>){}
    async register(createUserDto:User):Promise<User>{
        return await  new this.userModel(createUserDto).save()
    }
    async findByPhone(phone:string):Promise<User>{
        return this.userModel.findOne({phone}).exec()
    }
    async loginWithPassword(username:string,password:string):Promise<User>{
        return this.userModel.findOne({$or:[{username},{phone:username},{email:username}],password}).exec()
    }
}
